import {
  loanapply,
  getLoanApplyList,
  updateloanApplystate,
  myLoeanApply,
  mydebt,
  myRepayPlan,
  DefiniteRepayment,
  AccessInvestmentRecords,
  getTransactionRecord,
  ExpectedReturn,
  getIncome
} from "@/api/loan";

const actions = {
  // 借款申请
  loanapply({ commit }, data) {
    return new Promise((resolve, reject) => {
      loanapply(data)
        .then((response) => {
          resolve(); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 获取借款申请列表
  getLoanApplyList({ commit }, data) {
    return new Promise((resolve, reject) => {
      getLoanApplyList(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 审批借款（更新借款申请的状态）
  updateloanApplystate({ commit }, data) {
    return new Promise((resolve, reject) => {
      updateloanApplystate(data)
        .then((response) => {
          resolve(); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 我的借款
  myLoeanApply({ commit }, data) {
    return new Promise((resolve, reject) => {
      myLoeanApply(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 债权
  mydebt({ commit }, data) {
    return new Promise((resolve, reject) => {
      mydebt(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 还款计划的列表
  myRepayPlan({ commit }, data) {
    return new Promise((resolve, reject) => {
      myRepayPlan(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 确定还款
  DefiniteRepayment({ commit }, data) {
    return new Promise((resolve, reject) => {
      DefiniteRepayment(data)
        .then((response) => {
          resolve(); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 投资记录
  AccessInvestmentRecords({ commit }, data) {
    return new Promise((resolve, reject) => {
      AccessInvestmentRecords(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 交易记录
  getTransactionRecord({ commit }, data) {
    return new Promise((resolve, reject) => {
      getTransactionRecord(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 预期收益
  ExpectedReturn({ commit }, data) {
    return new Promise((resolve, reject) => {
      ExpectedReturn(data)
        .then((response) => {
          resolve(response.data.data); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },

  // 获得收益
  getIncome({ commit }, data) {
    return new Promise((resolve, reject) => {
      getIncome(data)
        .then((response) => {
          resolve(); // 置为成功
        })
        .catch((error) => {
          reject(error); // 报错
        });
    });
  },
};

// 导入
export default {
  namespaced: true, // 匿名空间，要打开
  actions,
};
